package com.ww.yaodao.controller;

import com.ww.yaodao.model.vo.announce.AnnouncementRespVO;
import com.ww.yaodao.model.vo.announce.AnnouncementVO;
import com.ww.yaodao.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wanziyan
 * @Date 2023-04-9:18
 */
@RestController
@RequestMapping("announcement")
@Slf4j
@Api(tags = "公告管理")
@RequiredArgsConstructor
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;
    @GetMapping("getAll")
    @ApiOperation("公告总览")
    public AnnouncementRespVO getAll(){
        log.info("进入公告总览....");
        return announcementService.getAllAnnounce();
    }

    @GetMapping("{id}")
    @ApiOperation("删除公告")
    public AnnouncementRespVO deleteById(@PathVariable("id") @ApiParam("删除公告id") Integer id){
        log.info("进入删除公告....");
        return announcementService.deleteAnnonce(id);
    }

    @PostMapping("/update")
    @ApiOperation("更新公告")
    public AnnouncementRespVO update(@RequestBody AnnouncementVO announcementVO){
        log.info("进入更新公告....");
        return announcementService.updateById(announcementVO);
    }

    @PostMapping("/add")
    @ApiOperation("添加公告")
    public AnnouncementRespVO add(@RequestBody AnnouncementVO announcementVO){
        log.info("进入添加公告....");
        return announcementService.addAnnouncement(announcementVO);
    }
}
